﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>下载服务器文件夹</title>
    <script type="text/javascript" src="js/jquery-1.4.min.js"></script>
    <script type="text/javascript" src="js/down.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/demo.js" charset="utf-8"></script>
    <style type="text/css">
        h5 {
            margin: 0;
            font-family: 微软雅黑 宋体;
        }

        p {
            font: 9pt 宋体;
        }

        ul {
            list-style-type: none;
            font: 9pt 宋体;
        }

        ul li {
            display: inline;
            margin: 0 5px 0 0;
            font: 9pt 宋体;
        }
    </style>
</head>
<body>
    <h5>下载服务器文件夹</h5>
    <div id="demos"></div>
    服务器文件夹路径：<input value="" id="path" />
    <input type="button" value="下载文件夹" id="btn-down-fd" />
    <div id="downDiv"></div>
    <script type="text/javascript" language="javascript">
        //根路径：http://localhost/api/up6/
        var pos = window.location.href.lastIndexOf("loc-dir.htm");
        var api = window.location.href.substr(0, pos) + "api/";
        var db = window.location.href.substr(0, pos) + "db/";
        var downer = new DownloaderMgr({
            config: {
                License2: "",//请在此处配置授权码
                Folder: "",
                DataBase: false,//启用数据库支持
                //api
                "UrlCreate": db + "d_create.aspx",
                "UrlDel": db + "d_del.aspx",
                "UrlList": db + "d_list.aspx",
                "UrlUpdate": db + "d_update.aspx",
                "UrlDown": db + "down.aspx"
            },
            event: {
                taskCreate: function (obj) {
                    $(document.body).append("文件ID：" + obj.fileSvr.id) + "<br/>";

                    //自动下载
                    setTimeout(function () {
                        if (obj.fields.auto == "1") downer.start_queue();
                    }, 300);
                },
                downProcess: function (obj) { },
                downStoped: function (obj) { },
                downComplete: function (obj) {
                    $(document.body).append('<div>本地路径：' + obj.fileSvr.pathLoc + '</div>');
                },
                downError: function (obj, err) { },
                queueComplete: function () {
                    $(document.body).append("<div>队列完成</div>");
                },
                //ready: function () { },
                selFolder: function (dir) {
                    setTimeout(function () {
                        if (downer.data.cur != null) {
                            downer.addJson(downer.data.cur);
                            downer.data.cur = null;
                        }
                    }, 100);
                }
            },
            ui: { render: "downDiv" }
        });

        $(function () {
            //下载多级目录
            $("#btn-down-fd").click(function () {
                $("#btn-down-fd").attr("disabled", true);
                $(document.body).append("<p>正在拉取数据" + api + "dir.aspx" + "</p>");
                var path = encodeURIComponent($("#path").val());

                $.ajax({
                    url: api + "dir.aspx?base64=1&path=" + path + "&t=" + new Date().getTime(),
                    type: "GET",
                    dataType: "json",
                    success: function (v) {

                        if (downer.Config["Folder"] == "") {
                            downer.data.cur = v;
                            downer.openFolder();
                            return;
                        }
                        downer.addJson(v);
                    },
                    error: function (req, sta, err) {
                        $(document.body).append("<p>" + err + " req.status:" + req.status + " req.readyState:" + req.readyState + "</p>");
                    }
                });
            });
        });
    </script>
</body>
</html>